/*
 * Copyright 2011 Stefan Ferstl
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.google.code.debmavenplugin.mojo;

import java.io.File;
import java.util.List;

import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

import com.google.code.debmavenplugin.archiver.ArchiveMetaData;



public class Data {

  /**
   * The directory containing the files for the debian package. The files in
   * this directory will end up in the <code>data.tar.gz</code> archive of the
   * debian package.
   * @parameter expression="${project.build.directory}/data-files"
   * @required
   * @readonly
   */
  private File baseDirectory;
  private String userName;
  private String groupName;
  private String dirMode;
  private String fileMode;
  private List<SpecialFile> specialFiles;
  private List<String> exclusions;


  public ArchiveMetaData createArchiveMetaData() {
    int dirMode = Integer.parseInt(this.dirMode, 8);
    int fileMode = Integer.parseInt(this.fileMode, 8);
    ArchiveMetaData metaData = new ArchiveMetaData(this.baseDirectory, this.userName, this.groupName, dirMode, fileMode);
    if (this.specialFiles != null) {
      for (SpecialFile sf : this.specialFiles) {
        metaData.addSpecialFile(
            sf.getFileName(), sf.getUserName(), sf.getGroupName(), sf.getFileMode());
      }
    }

    if (this.exclusions != null) {
      for (String exclusion : this.exclusions) {
        metaData.addExclusion(exclusion);

      }
    }
    return metaData;

  }

  @Override
  public String toString() {
    return ToStringBuilder.reflectionToString(this, ToStringStyle.SIMPLE_STYLE);
  }
}
